from django.core.management.base import BaseCommand,CommandError
from app.models.userModel import User
from django.forms.models import model_to_dict
from app.models.categoryModel import Category
from app.models.contentModel import Content

class Command(BaseCommand):
    help = 'self define command'

    def handle(self, *args, **options):
        # print('hi, this is zhang')
        # self.add()
        # self.update()
        self.select()

    def add(self):
        #user = Users(name='zhang', mobile='14785757671', city='beijing')
        #user.save()
        #print(user.id)
        category = Category()
        category.name = '动物'
        category.img = 'hello.png'
        category.save()

        content = Content()
        content.name = '马'
        content.img = 'ma.png'
        content.category = category
        content.audio = 'ma.mp3'
        content.video = 'ma.mp4'
        content.save()



    def update(self):
        user = User.objects.get(id=1)
        user.name = 'zhangweixi'
        user.save()

    def select(self):
        import logging
        logger = logging.getLogger(__name__)
        logger.info('this is a debug info')

        users = User.objects.all().values()
        print(users[0]['created_at'])
        print(list(users))

        category = Category.objects.all().values()
        print(list(category))

        content = Content.objects.all().values()
        print(list(content))

